package org.example.springoauth2.securitycommon.config.authenticate.grant.tt;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @author hzq
 * @since 2021-09-11
 */
public class TtAuthenticationToken extends AbstractAuthenticationToken {

    private Object principal;

    public TtAuthenticationToken(String openid) {
        super(AuthorityUtils.NO_AUTHORITIES);
        this.principal = openid;
    }

    public TtAuthenticationToken(UserDetails sysUser) {
        super(sysUser.getAuthorities());
        this.principal = sysUser;
        super.setAuthenticated(true); // 设置认证成功 必须
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public Object getCredentials() {
        return null;
    }
}
